//
//  CommitProblemViewController.m
//  AnXin100
//
//  Created by Sakura on 2018/11/5.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "CommitProblemViewController.h"

#import "JJOptionView.h"
#import "ChoicePhotoView.h"
@interface CommitProblemViewController ()

@property (nonatomic, strong) ChoicePhotoView *choicePhoto;

@end

@implementation CommitProblemViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self setupNavigationItems];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    NSArray *array = @[@{@"title" : @"作物",
                         @"name" : @"请选择作物"},
                       @{@"title" : @"品种",
                         @"name" : @"请选择品种"},
                       @{@"title" : @"问题分类",
                         @"name" : @"选择问题分类"},
                       @{@"title" : @"症状说明",
                         @"name" : @"请描述您作物出现的症状"},
                       @{@"title" : @"上传照片视频",
                         @"name" : @""}];
    
    for (NSInteger i = 0; i < array.count; i++) {
        
        if (i < array.count - 2) {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 64 + 50 * i, SCREEN_WIDTH, 50)];
            view.backgroundColor = [UIColor whiteColor];
            
            UILabel *nameLabel = [UILabel getCustomLabel:[UIColor colorWithHex:0x333333] font:FONT_SIXTEEN rect:CGRectMake(10, 0, 120, 50)];
            nameLabel.text = array[i][@"title"];
            [view addSubview:nameLabel];
            
            JJOptionView *selecView = [[JJOptionView alloc] initWithFrame:CGRectMake(140, 10, 200, 30)];
            selecView.dataSource = @[@"111",@"222",@"333",@"444",@"555"];
            selecView.title = array[i][@"name"];
            selecView.selectedBlock = ^(JJOptionView * _Nonnull optionView, NSInteger selectedIndex) {
                NSLog(@"%@",optionView);
                NSLog(@"%ld",selectedIndex);
            };
            [view addSubview:selecView];
            [self.view addSubview:view];
        } else if (i == array.count - 2) {
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 64 + 50 * i, SCREEN_WIDTH, 100)];
            UILabel *nameLabel = [UILabel getCustomLabel:[UIColor colorWithHex:0x333333] font:FONT_SIXTEEN rect:CGRectMake(10, 0, 120, 50)];
            nameLabel.text = array[i][@"title"];
            [view addSubview:nameLabel];
            
            UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(140, 10, SCREEN_WIDTH - 160, 90)];
            textView.layer.cornerRadius = 5;
            textView.layer.borderColor = [UIColor colorWithHex:0xf6f6f6].CGColor;
            textView.layer.borderWidth = 1;
            [view addSubview:textView];
            [self.view addSubview:view];
        } else {
            
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 64 + 50 * (i - 1) + 110, SCREEN_WIDTH, 300)];
            UILabel *nameLabel = [UILabel getCustomLabel:[UIColor colorWithHex:0x333333] font:FONT_SIXTEEN rect:CGRectMake(10, 0, 120, 50)];
            nameLabel.text = array[i][@"title"];
            [view addSubview:nameLabel];
            [self.view addSubview:view];
            
            _choicePhoto = [[ChoicePhotoView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
            _choicePhoto.viewController = self;
            _choicePhoto.takingPictures = YES;
            _choicePhoto.choicePictures = YES;
            _choicePhoto.choiceViedos = NO;
            _choicePhoto.orginalImage = NO;
            _choicePhoto.GIF = NO;
            _choicePhoto.takeBtn = YES;
            _choicePhoto.tailoring = NO;
            _choicePhoto.CircularCut = NO;
            _choicePhoto.multiSelectViedoAndGif = NO;
            _choicePhoto.recordViedo = NO;
            _choicePhoto.showNumber = YES;
            _choicePhoto.maxChoiceImage = 9;
            _choicePhoto.lineImageNumber = 4;
            _choicePhoto.type = Transverse;
            [view addSubview:_choicePhoto];
        }

    }
    
    
    
    UIButton *btn = [[UIButton alloc]init];
    [btn addTarget:self action:@selector(submit:) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = COLOR_GREEN;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btn setTitle:@"提交" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:btn];
    
    btn.sd_layout
    .leftSpaceToView(self.view, 0)
    .bottomSpaceToView(self.view, 0)
    .rightSpaceToView(self.view, 0)
    .heightIs(40);
    
    

}

#pragma mark - action

- (void)submit:(UIButton *)btn {
    
}




- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    //返回按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 60, 30);
    [kfBtn addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.textColor = [UIColor colorWithHex:0x29b566];
    titleLabel.text = @"提交问题";
    self.navigationItem.titleView = titleLabel;
    
    
    
}

#pragma mark - Action

- (void)backAction:(UIBarButtonItem *)item {
    [self.navigationController popViewControllerAnimated:YES];
}


//点击空白处收起键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self.view endEditing:YES];
}

@end
